<template>
	<view class="pages">
		<h-nav-bar-yun title="问诊设置" :fixed="true" rightText="保存" @clickLeft="clickLeft" @clickRight="submit"></h-nav-bar-yun>
		<view class="section">
			<view class="sec_title">价格设置</view>
			<view class="sec_ti">
				<image src="@/static/index/tishi.png"></image>目前仅支持一年修改2次问诊价格
			</view>
			<view v-for="(item,index) in quoteList" :key="index">
				<view class="sec_tt">{{item.group_name}}</view>
				<view class="sec_num" @click="toPrtce(item.unit_price,index)">￥<text :style="{color:(item.unit_price?'#202020':'#aaa')}">{{item.unit_price||'请输入'}}</text></view>
			</view>
		</view>
	</view>
	<h-num-keyboard-new @touchmove.stop.prevent="moveHandle" :show="priceShow" :num="mealNum" @bind="bindNum" @clear="clearNum"></h-num-keyboard-new>
	<h-modal :show="saveShow" titlea="修改内容未保存" leftBtn="直接离开" rightBtn="保存后离开" @clear="navigateBack()" @bind="submit"></h-modal>
</template>

<script setup lang="ts">
	import { ref, reactive, nextTick } from 'vue'
	import { formatDate } from '@/utils/utils'
	import { getDoctorQuoteDetails, getSetConsultationQuote, getManServiceList } from '@/api/business'
	import { navigateTo, showToast, navigateBack, redirectTo } from '@/utils'
	import {
		onLoad,
		onPullDownRefresh,
		onReachBottom,
		onReady,
		onShow,
		onPageScroll,
		onUnload,
		onHide,
		onBackPress,
	} from '@dcloudio/uni-app'
	import { uploadApi } from '@/utils/upLoad'
	import { useMemberStore } from '@/stores'
	const login = ref(null) // 登录组件实例
	const store = useMemberStore()
	let token = store?.token
	let props = defineProps({
		setType: String,
	})
	const freeTime = ref('')
	const statusHeight = ref(0)
	const dIndex = ref(0)
	const priceShow = ref(false)
	const mealNum = ref('')
	const unitPrice = ref("")
	const isUpdate = ref(false)
	const saveShow = ref(false)
	const quoteList = ref([])
	onLoad((o) => {
		getMan()
	})
	onShow(() => {})
	onReady(() => {
		uni.getSystemInfo({
			success: (e) => {
				statusHeight.value = e.statusBarHeight * 2
			},
		})
	})

	async function getMan() {
		const res = await getManServiceList({
			type: 1
		})
		quoteList.value = res.data.data.data.quoteList
		console.log(quoteList.value)
	}

	function clickLeft() {
		if(isUpdate.value) {
			saveShow.value = true
		} else {
			navigateBack()
		}
	}

	function toPrtce(num, index) {
		dIndex.value = index
		mealNum.value = num.toString()
		priceShow.value = true
	}

	function clearNum() {
		priceShow.value = false
	}

	function moveHandle() {
		return false
	}

	function bindNum(e) {
		console.log(e)
		if(Number(e)==0){
			showToast("价格不能设置为0元")
			return false;
		}
		priceShow.value = false
		isUpdate.value = true
		quoteList.value[dIndex.value].unit_price = e
	}
	async function submit() {
		const list=quoteList.value;
		let arr=[]
		for(var i in list){
			arr.push({
				group_id:list[i].group_id,
				unit_price:list[i].unit_price
			})
		}
		const res = await getSetConsultationQuote({
			service_data:arr
		})
		if(res.code == 200) {
			navigateBack()
			uni.setStorageSync('priceSet', true)
			uni.setStorageSync('priceSetId', 2)
		} else {
			showToast(res.message)
		}
	}
</script>

<style>
	page {
		background: #F5F6F8;
	}
</style>
<style lang="scss" scoped>
	.over_page {
		height: 98vh !important;
		overflow: hidden !important;
	}
	
	.flex {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
	}
	
	.flex_cen {
		display: flex;
		flex-direction: row;
		/* 子元素横向排列 */
		justify-content: center;
		/* 相对父元素水平居中 */
		align-items: center;
	}
	
	.flex_line {
		display: flex;
		flex-direction: row;
		/* 子元素横向排列 */
		justify-content: center;
		/* 相对父元素水平居中 */
		align-items: stretch;
	}
	
	.clear:after {
		/*START 真正起到清除浮动的代码*/
		content: '';
		display: block;
		clear: both;
		/*END 真正起到清除浮动的代码*/
		height: 0;
	}
	
	.clear {
		display: inline-block;
	}
	
	.left {
		float: left;
	}
	
	.right {
		float: right;
	}
	
	.section {
		width: 702rpx;
		background: #FFF;
		margin: 20rpx auto;
		overflow: hidden;
		box-sizing: border-box;
		padding: 10rpx 24rpx 0;
		.sec_title {
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			font-size: 30rpx;
			color: #202020;
			line-height: 42rpx;
			text-align: left;
			font-style: normal;
			padding: 10rpx 0;
		}
		.sec_ti {
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			font-size: 26rpx;
			color: #f5a520;
			line-height: 37rpx;
			padding: 10rpx 0;
			image {
				width: 26rpx;
				height: 26rpx;
				margin: 0 6rpx;
				position: relative;
				top: 4rpx;
			}
		}
		.sec_tt {
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 26rpx;
			color: #202020;
			line-height: 36rpx;
			text-align: left;
			font-style: normal;
			text-transform: none;
			padding-top: 40rpx;
		}
		.sec_num {
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 30rpx;
			color: #202020;
			line-height: 120rpx;
			text-align: left;
			font-style: normal;
			text-transform: none;
		}
	}
</style>